﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EmbeddedSharp.Core.TextConentProviders;
using Zove.Runtime.Core;
using Zove.Runtime.Core.Zoom;

namespace Zove.Runtime.Test.Zoom {
    /// <summary>
    /// Summary description for ZoomLanguageTests
    /// </summary>
    [TestClass]
    public class ZoomLanguageTests {
        public ZoomLanguageTests() {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext {
            get {
                return testContextInstance;
            }
            set {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestArray() {
            const string source = @"
class ArrayTest {
    factor n;
    factor[n] ranges;

    for(i=0, i<n, i=i+1, ranges[i]=ranges[(i+1)%n]*2);
}";

            StringContentProvider contentProvider = new StringContentProvider(source);
            ZoomLanguageNature languageNature = new ZoomLanguageNature();

            ZoveObject zoveObject = new ZoveObject(string.Empty, contentProvider, languageNature);
            Console.WriteLine(zoveObject.Where().Select("", ""));
        }

        [TestMethod]
        public void TestPackageAndImport()
        {
            const string source = @"
packge DemoPackage;

class Demo {
    
}
";
        }

        [TestMethod]
        public void TestObjectQuery() {
            ZoomLanguageNature languageNature = new ZoomLanguageNature();
            ClassContentProvider contentProvider = new ClassContentProvider("circle", languageNature);

            ZoveObject zoveObject = new ZoveObject(string.Empty, contentProvider, languageNature);
            zoveObject.Where("r=10").Assert("area=314.15926", "c=62.831852");
        }

        [TestMethod]
        [Ignore]
        public void TestLinqToZove() {
            ZoomLanguageNature languageNature = new ZoomLanguageNature();
            ZoveObject circle = new ZoveObject(string.Empty, new ClassContentProvider("circle", languageNature), languageNature);

            var results = from factor in circle.Model.Factors where factor.Name == "r" && factor.Value == 10 select factor.Name == "area";
        }

        [TestMethod]
        [Ignore]
        public void TestLinq() {
            int[] array = { 1, 2, 3, 4, 5 };

            var ret = from e in array where e < 3 select e;

            Dictionary<double, double> coll = new Dictionary<double, double>();
            coll.Add(1, 1);
            coll.Add(2, 2);
            coll.Add(3, 3);

            var ret2 = from c in coll where c.Key < 3 select c;
        }
    }
}
